//
// Created by Semir on 2020/4/23.
//

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

struct Candidate {
    string vote;
    int id;
};

int n;
//string votes[25];
Candidate candidates[25];

bool cmp(Candidate c1, Candidate c2) {
    if (c1.vote.length() > c2.vote.length()) {
        return true;
    } else if (c1.vote.length() < c2.vote.length()) {
        return false;
    }
    return c1.vote + c2.vote >= c2.vote + c1.vote;
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        candidates[i].id = i;
        cin >> candidates[i].vote;
    }
    sort(candidates + 1, candidates + 1 + n, cmp);
    cout << candidates[1].id << endl;
    cout << candidates[1].vote;
    return 0;
}